<%@ page import="com.wang.servlet.LoginServlet" %><%--
  Created by IntelliJ IDEA.
  User: wr
  Date: 2021/10/29
  Time: 17:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Login</title>
    <script src="https://unpkg.zhimg.com/axios/dist/axios.min.js"></script>
</head>
<body>
<div>
    <div>
        <table>
            <tr>
                <td>
                    <input placeholder="请输入用户名" id="user" type="text" max="10">
                </td>
            </tr>
            <tr>
                <td>
                    <input type="button" value="登录" onclick="login(document.getElementById('user').value)">
                </td>
            </tr>
        </table>

    </div>
</div>
</body>
<script>
    function login(user) {
        if (user === null || user === "") {
            alert("未填写用户名")
        } else {
            let path = new RegExp("[\/,\.]");

            if (path.test(user)) {
                alert("用户名不可为文件名")
            } else {
                axios.get("/login", {
                    params: {
                        user: user
                    }
                }).then(res => {
                    if (res.status === 200) {
                        window.location.href = 'home.jsp'
                    }
                })
            }
        }
    }
</script>
</html>
